import { extname } from 'path'

// https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
// https://code.visualstudio.com/docs/languages/identifiers
const languages = new Map<string, string>([
  ['bat', 'bat'],
  ['cmd', 'bat'],

  ['bib', 'bibtex'],

  ['clj', 'clojure'],
  ['boot', 'clojure'],
  ['cl2', 'clojure'],
  ['cljc', 'clojure'],
  ['cljs', 'clojure'],
  ['cljs.hl', 'clojure'],
  ['cljscm', 'clojure'],
  ['cljx', 'clojure'],
  ['hic', 'clojure'],

  ['coffee', 'coffeescript'],
  ['_coffee', 'coffeescript'],
  ['cjsx', 'coffeescript'],
  ['iced', 'coffeescript'],

  ['c', 'c'],
  ['h', 'c'],
  ['cats', 'c'],
  ['idc', 'c'],

  ['cpp', 'cpp'],
  ['c++', 'cpp'],
  ['cc', 'cpp'],
  ['cp', 'cpp'],
  ['cxx', 'cpp'],
  ['h', 'cpp'],
  ['h++', 'cpp'],
  ['hh', 'cpp'],
  ['hpp', 'cpp'],
  ['hxx', 'cpp'],
  ['inc', 'cpp'],
  ['inl', 'cpp'],
  ['ipp', 'cpp'],
  ['re', 'cpp'],
  ['tcc', 'cpp'],
  ['tpp', 'cpp'],

  ['cs', 'csharp'],
  ['cake', 'csharp'],
  ['csx', 'csharp'],

  ['css', 'css'],

  ['diff', 'diff'],
  ['patch', 'diff'],

  ['dockerfile', 'dockerfile'],

  ['fs', 'fsharp'],
  ['fsi', 'fsharp'],
  ['fsx', 'fsharp'],

  ['go', 'go'],

  ['groovy', 'groovy'],
  ['grt', 'groovy'],
  ['gtpl', 'groovy'],
  ['gvy', 'groovy'],

  ['handlebars', 'handlebars'],
  ['hbs', 'handlebars'],

  ['html', 'html'],
  ['htm', 'html'],
  ['html.hl', 'html'],
  ['inc', 'html'],
  ['st', 'html'],
  ['xht', 'html'],
  ['xhtml', 'html'],

  ['ini', 'ini'],
  ['cfg', 'ini'],
  ['prefs', 'ini'],
  ['pro', 'ini'],
  ['properties', 'ini'],

  ['java', 'java'],

  ['js', 'javascript'],
  ['_js', 'javascript'],
  ['bones', 'javascript'],
  ['es', 'javascript'],
  ['es6', 'javascript'],
  ['frag', 'javascript'],
  ['gs', 'javascript'],
  ['jake', 'javascript'],
  ['jsb', 'javascript'],
  ['jscad', 'javascript'],
  ['jsfl', 'javascript'],
  ['jsm', 'javascript'],
  ['jss', 'javascript'],
  ['mjs', 'javascript'],
  ['njs', 'javascript'],
  ['pac', 'javascript'],
  ['sjs', 'javascript'],
  ['ssjs', 'javascript'],
  ['xsjs', 'javascript'],
  ['xsjslib', 'javascript'],

  ['json', 'json'],

  ['tex', 'latex'],
  ['aux', 'latex'],
  ['bbx', 'latex'],
  ['bib', 'latex'],
  ['cbx', 'latex'],
  ['cls', 'latex'],
  ['dtx', 'latex'],
  ['ins', 'latex'],
  ['lbx', 'latex'],
  ['ltx', 'latex'],
  ['mkii', 'latex'],
  ['mkiv', 'latex'],
  ['mkvi', 'latex'],
  ['sty', 'latex'],
  ['toc', 'latex'],

  ['less', 'less'],

  ['lua', 'lua'],
  ['fcgi', 'lua'],
  ['nse', 'lua'],
  ['pd_lua', 'lua'],
  ['rbxs', 'lua'],
  ['wlua', 'lua'],

  ['Makefile', 'makefile'],
  ['makefile', 'makefile'],
  ['mak', 'makefile'],
  ['d', 'makefile'],
  ['make', 'makefile'],
  ['mk', 'makefile'],
  ['mkfile', 'makefile'],

  ['md', 'markdown'],
  ['markdown', 'markdown'],
  ['mdown', 'markdown'],
  ['mdwn', 'markdown'],
  ['mkd', 'markdown'],
  ['mkdn', 'markdown'],
  ['mkdown', 'markdown'],
  ['ron', 'markdown'],
  ['workbook', 'markdown'],

  ['m', 'objective-c'],
  ['h', 'objective-c'],

  ['mm', 'objective-cpp'],

  ['pl', 'perl'],
  ['al', 'perl'],
  ['cgi', 'perl'],
  ['fcgi', 'perl'],
  ['perl', 'perl'],
  ['ph', 'perl'],
  ['plx', 'perl'],
  ['pm', 'perl'],
  ['pod', 'perl'],
  ['psgi', 'perl'],
  ['t', 'perl'],

  ['6pl', 'perl6'],
  ['6pm', 'perl6'],
  ['nqp', 'perl6'],
  ['p6', 'perl6'],
  ['p6l', 'perl6'],
  ['p6m', 'perl6'],
  ['pl', 'perl6'],
  ['pl6', 'perl6'],
  ['pm', 'perl6'],
  ['pm6', 'perl6'],
  ['t', 'perl6'],

  ['php', 'php'],
  ['aw', 'php'],
  ['ctp', 'php'],
  ['fcgi', 'php'],
  ['inc', 'php'],
  ['php3', 'php'],
  ['php4', 'php'],
  ['php5', 'php'],
  ['phps', 'php'],
  ['phpt', 'php'],

  ['ps1', 'powershell'],
  ['psd1', 'powershell'],
  ['psm1', 'powershell'],

  ['jade', 'jade'],
  ['pug', 'jade'],

  ['py', 'python'],
  ['bzl', 'python'],
  ['cgi', 'python'],
  ['fcgi', 'python'],
  ['gyp', 'python'],
  ['gypi', 'python'],
  ['lmi', 'python'],
  ['py3', 'python'],
  ['pyde', 'python'],
  ['pyi', 'python'],
  ['pyp', 'python'],
  ['pyt', 'python'],
  ['pyw', 'python'],
  ['rpy', 'python'],
  ['spec', 'python'],
  ['tac', 'python'],
  ['wsgi', 'python'],
  ['xpy', 'python'],

  ['r', 'r'],
  ['rd', 'r'],
  ['rsx', 'r'],

  ['cshtml', 'razor'],

  ['rb', 'ruby'],
  ['builder', 'ruby'],
  ['eye', 'ruby'],
  ['fcgi', 'ruby'],
  ['gemspec', 'ruby'],
  ['god', 'ruby'],
  ['jbuilder', 'ruby'],
  ['mspec', 'ruby'],
  ['pluginspec', 'ruby'],
  ['podspec', 'ruby'],
  ['rabl', 'ruby'],
  ['rake', 'ruby'],
  ['rbuild', 'ruby'],
  ['rbw', 'ruby'],
  ['rbx', 'ruby'],
  ['ru', 'ruby'],
  ['ruby', 'ruby'],
  ['spec', 'ruby'],
  ['thor', 'ruby'],
  ['watchr', 'ruby'],

  ['rs', 'rust'],
  ['rs.in', 'rust'],

  ['scss', 'scss'],
  ['sass', 'sass'],

  ['shader', 'shaderlab'],

  ['pls', 'sql'],
  ['bdy', 'sql'],
  ['ddl', 'sql'],
  ['fnc', 'sql'],
  ['pck', 'sql'],
  ['pkb', 'sql'],
  ['pks', 'sql'],
  ['plb', 'sql'],
  ['plsql', 'sql'],
  ['prc', 'sql'],
  ['spc', 'sql'],
  ['sql', 'sql'],
  ['tpb', 'sql'],
  ['tps', 'sql'],
  ['trg', 'sql'],
  ['vw', 'sql'],
  ['cql', 'sql'],
  ['mysql', 'sql'],
  ['tab', 'sql'],
  ['udf', 'sql'],
  ['viw', 'sql'],
  ['db2', 'sql'],

  ['swift', 'swift'],

  ['ts', 'typescript'],
  ['tsx', 'typescript'],

  ['vb', 'vb'],
  ['bas', 'vb'],
  ['cls', 'vb'],
  ['frm', 'vb'],
  ['frx', 'vb'],
  ['vba', 'vb'],
  ['vbhtml', 'vb'],
  ['vbs', 'vb'],

  ['xml', 'xml'],
  ['adml', 'xml'],
  ['admx', 'xml'],
  ['ant', 'xml'],
  ['axml', 'xml'],
  ['builds', 'xml'],
  ['ccproj', 'xml'],
  ['ccxml', 'xml'],
  ['clixml', 'xml'],
  ['cproject', 'xml'],
  ['cscfg', 'xml'],
  ['csdef', 'xml'],
  ['csl', 'xml'],
  ['csproj', 'xml'],
  ['ct', 'xml'],
  ['depproj', 'xml'],
  ['dita', 'xml'],
  ['ditamap', 'xml'],
  ['ditaval', 'xml'],
  ['dll.config', 'xml'],
  ['dotsettings', 'xml'],
  ['filters', 'xml'],
  ['fsproj', 'xml'],
  ['fxml', 'xml'],
  ['glade', 'xml'],
  ['gml', 'xml'],
  ['grxml', 'xml'],
  ['iml', 'xml'],
  ['ivy', 'xml'],
  ['jelly', 'xml'],
  ['jsproj', 'xml'],
  ['kml', 'xml'],
  ['launch', 'xml'],
  ['mdpolicy', 'xml'],
  ['mjml', 'xml'],
  ['mm', 'xml'],
  ['mod', 'xml'],
  ['mxml', 'xml'],
  ['natvis', 'xml'],
  ['ndproj', 'xml'],
  ['nproj', 'xml'],
  ['nuspec', 'xml'],
  ['odd', 'xml'],
  ['osm', 'xml'],
  ['pkgproj', 'xml'],
  ['plist', 'xml'],
  ['pluginspec', 'xml'],
  ['proj', 'xml'],
  ['props', 'xml'],
  ['ps1xml', 'xml'],
  ['psc1', 'xml'],
  ['pt', 'xml'],
  ['rdf', 'xml'],
  ['resx', 'xml'],
  ['rss', 'xml'],
  ['sch', 'xml'],
  ['scxml', 'xml'],
  ['sfproj', 'xml'],
  ['shproj', 'xml'],
  ['srdf', 'xml'],
  ['storyboard', 'xml'],
  ['stTheme', 'xml'],
  ['sublime-snippet', 'xml'],
  ['targets', 'xml'],
  ['tmCommand', 'xml'],
  ['tml', 'xml'],
  ['tmLanguage', 'xml'],
  ['tmPreferences', 'xml'],
  ['tmSnippet', 'xml'],
  ['tmTheme', 'xml'],
  ['ui', 'xml'],
  ['urdf', 'xml'],
  ['ux', 'xml'],
  ['vbproj', 'xml'],
  ['vcxproj', 'xml'],
  ['vsixmanifest', 'xml'],
  ['vssettings', 'xml'],
  ['vstemplate', 'xml'],
  ['vxml', 'xml'],
  ['wixproj', 'xml'],
  ['wsdl', 'xml'],
  ['wsf', 'xml'],
  ['wxi', 'xml'],
  ['wxl', 'xml'],
  ['wxs', 'xml'],
  ['x3d', 'xml'],
  ['xacro', 'xml'],
  ['xaml', 'xml'],
  ['xib', 'xml'],
  ['xlf', 'xml'],
  ['xliff', 'xml'],
  ['xmi', 'xml'],
  ['xml.dist', 'xml'],
  ['xproj', 'xml'],
  ['xsd', 'xml'],
  ['xspec', 'xml'],
  ['xul', 'xml'],
  ['zcml', 'xml'],

  ['xsl', 'xsl'],
  ['xslt', 'xsl'],

  ['yml', 'yaml'],
  ['reek', 'yaml'],
  ['rviz', 'yaml'],
  ['sublime-syntax', 'yaml'],
  ['syntax', 'yaml'],
  ['yaml', 'yaml'],
  ['yaml-tmlanguage', 'yaml'],
  ['yml.mysql', 'yaml'],

  ['sh', 'shellscript'],
  ['bash', 'shellscript'],
  ['bats', 'shellscript'],
  ['cgi', 'shellscript'],
  ['command', 'shellscript'],
  ['fcgi', 'shellscript'],
  ['ksh', 'shellscript'],
  ['sh.in', 'shellscript'],
  ['tmux', 'shellscript'],
  ['tool', 'shellscript'],
  ['zsh', 'shellscript'],
  ['bash_history', 'shellscript'],
  ['bash_logout', 'shellscript'],
  ['bash_profile', 'shellscript'],
  ['bashrc', 'shellscript'],
])

export const getLanguageForExtension = (ext: string) => languages.get(ext)
export default (path: string): string => (languages.get(extname(path)) || '').replace(/^\./, '')
